package demo.controller;



import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo.common.Result;
import demo.entity.One;
import demo.entity.University;
import demo.entity.Universitymajor;
import demo.entity.Universitymajor2;
import demo.mapper.LimitmajorMapper;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;

@CrossOrigin(maxAge = 36000)
@RestController
@RequestMapping("/limitmajor")
public class LimitMajor {
  @Resource
  LimitmajorMapper limitmajorMapper;

//  @GetMapping
//  public Result<?> findmajor(@RequestParam(defaultValue = "1") Integer pageNum,
//                            @RequestParam(defaultValue = "20") Integer pageSize,
//                            @RequestParam(defaultValue = "") String search) {
//    LambdaQueryWrapper<Universitymajor> wrapper = Wrappers.<Universitymajor>lambdaQuery();
//    if (StrUtil.isNotBlank(search)) {
//      wrapper.like(Universitymajor::getUniversity, search);
//    }
//    Page<?> userPage = limitmajorMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
//
//    return Result.success(userPage);
//  }



  //(这个是可以查询的，但是没有关键词)
//  @GetMapping
//  public Result<?> findmajor(@RequestParam(defaultValue = "1") Integer pageNum,
//                             @RequestParam(defaultValue = "10") Integer pageSize,
//                             @RequestParam(defaultValue = "") String search){
//
//    Page<Universitymajor2> universitymajorList = limitmajorMapper.findmajor(new Page<>(pageNum, pageSize));
//    return Result.success(universitymajorList);
//  }


  @GetMapping
  public Result<?> findmajor(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             @RequestParam(defaultValue = "") String search){
    LambdaQueryWrapper<University> wrapper = Wrappers.<University>lambdaQuery();
    if(StrUtil.isNotBlank(search)){
      wrapper.like(University::getUnname , search);
    }
    System.out.println(Result.success(wrapper));
    Page<Universitymajor2> universitymajor2Page = limitmajorMapper.findmajor(new Page<>(pageNum,pageSize),wrapper);
    return Result.success(universitymajor2Page);
  }
}
